# Locate OSG
# This module defines
# OSG_LIBRARY
# OSG_FOUND, if false, do not try to link to OSG
# OSG_INCLUDE_DIR, where to find the headers
#
# $OSG_DIR is an environment variable that would
# correspond to the ./configure --prefix=$OSG_DIR
#
# Created by Robert Osfield
#   with revisions by the Delta3D team.


SET(OSG_ROOT ${DELTA3D_ROOT} CACHE PATH "OSG Path" )


FIND_PATH(OSG_INCLUDE_DIR osg/Node
    PATH_SUFFIXES inc include Frameworks win64 win64/inc
    HINTS
    ${OSG_ROOT}
    $ENV{OSG_DIR}
    $ENV{OSGDIR}
    $ENV{OSG_ROOT}
    ${CMAKE_SOURCE_DIR}/ext/win64
    ${CMAKE_SOURCE_DIR}/ext/win32
    ${DELTA3D_EXT_DIR}
    $ENV{DELTA_ROOT}/ext
    ${VSP_PROJECT_DIR}/ext
)
MARK_AS_ADVANCED(OSG_INCLUDE_DIR)

MACRO(FIND_OSG_LIBRARY MYLIBRARY MYLIBRARYNAME)
    FIND_LIBRARY(${MYLIBRARY}
        NAMES ${MYLIBRARYNAME}
        PATH_SUFFIXES lib build/lib lib64 build/lib64 win64 win64/lib Frameworks
        PATHS
        ${OSG_ROOT}
        $ENV{OSG_DIR}
        $ENV{OSGDIR}
        $ENV{OSG_ROOT}
        ${DELTA3D_EXT_DIR}
        $ENV{DELTA_ROOT}/ext
        ${VSP_PROJECT_DIR}/ext
    )
    MARK_AS_ADVANCED(${MYLIBRARY})

ENDMACRO(FIND_OSG_LIBRARY LIBRARY LIBRARYNAME)

# Find release (optimized) libs
FIND_OSG_LIBRARY(OSG_LIBRARY osg)
FIND_OSG_LIBRARY(OSGANIMATION_LIBRARY osgAnimation)
FIND_OSG_LIBRARY(OSGUTIL_LIBRARY osgUtil)
FIND_OSG_LIBRARY(OSGDB_LIBRARY osgDB)
FIND_OSG_LIBRARY(OSGTEXT_LIBRARY osgText)
FIND_OSG_LIBRARY(OSGTERRAIN_LIBRARY osgTerrain)
FIND_OSG_LIBRARY(OSGFX_LIBRARY osgFX)
FIND_OSG_LIBRARY(OSGVIEWER_LIBRARY osgViewer)
FIND_OSG_LIBRARY(OSGGA_LIBRARY osgGA)
FIND_OSG_LIBRARY(OSGPARTICLE_LIBRARY osgParticle)
FIND_OSG_LIBRARY(OSGSIM_LIBRARY osgSim)
FIND_OSG_LIBRARY(OSGSHADOW_LIBRARY osgShadow)
FIND_OSG_LIBRARY(OSGANIMATION_LIBRARY osgAnimation)
#FIND_OSG_LIBRARY(OSGEPHEMERIS_LIBRARY osgEphemeris)
FIND_OSG_LIBRARY(OSGVOLUME_LIBRARY osgVolume)
FIND_OSG_LIBRARY(OSGMANIPULATOR_LIBRARY osgManipulator)
FIND_OSG_LIBRARY(OSGWIDGET_LIBRARY osgWidget)
FIND_OSG_LIBRARY(OPENTHREADS_LIBRARY OpenThreads)

# Find debug libs
FIND_OSG_LIBRARY(OSG_LIBRARY_DEBUG osgd)
FIND_OSG_LIBRARY(OSGANIMATION_LIBRARY_DEBUG osgAnimationd)
FIND_OSG_LIBRARY(OSGUTIL_LIBRARY_DEBUG osgUtild)
FIND_OSG_LIBRARY(OSGDB_LIBRARY_DEBUG osgDBd)
FIND_OSG_LIBRARY(OSGTEXT_LIBRARY_DEBUG osgTextd)
FIND_OSG_LIBRARY(OSGTERRAIN_LIBRARY_DEBUG osgTerraind)
FIND_OSG_LIBRARY(OSGFX_LIBRARY_DEBUG osgFXd)
FIND_OSG_LIBRARY(OSGVIEWER_LIBRARY_DEBUG osgViewerd)
FIND_OSG_LIBRARY(OSGGA_LIBRARY_DEBUG osgGAd)
FIND_OSG_LIBRARY(OSGPARTICLE_LIBRARY_DEBUG osgParticled)
FIND_OSG_LIBRARY(OSGSIM_LIBRARY_DEBUG osgSimd)
FIND_OSG_LIBRARY(OSGSHADOW_LIBRARY_DEBUG osgShadowd)
FIND_OSG_LIBRARY(OSGANIMATION_LIBRARY_DEBUG osgAnimationd)
#FIND_OSG_LIBRARY(OSGEPHEMERIS_LIBRARY_DEBUG osgEphemerisd)
FIND_OSG_LIBRARY(OSGVOLUME_LIBRARY_DEBUG osgVolume)
FIND_OSG_LIBRARY(OSGMANIPULATOR_LIBRARY_DEBUG osgManipulatord)
FIND_OSG_LIBRARY(OSGWIDGET_LIBRARY_DEBUG osgWidgetd)
FIND_OSG_LIBRARY(OPENTHREADS_LIBRARY_DEBUG OpenThreadsd)

SET(OSG_FOUND "NO")
IF(OSG_LIBRARY AND OSG_INCLUDE_DIR)
    SET(OSG_FOUND "YES")
ENDIF(OSG_LIBRARY AND OSG_INCLUDE_DIR)
